URL = "http://download.gna.org/cal3d/sources/cal3d-%(VERSION)s.tar.gz"
VERSIONS = ["0.11.0"]
DEFAULT_VERSION = "0.11.0"

#def getcal3ddir(machine, directories):
#  return directories.enviro+"\\"+"cal3d-"+CAL3D_VERSION

from source.builders import VisualStudioBuilder, ConfigureMakeBuilder
import os, subprocess, sys


class Cal3dBuilder( VisualStudioBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """

  def configure(self):
    os.chdir( self.extractedpath+"\\src\\cal3d\\" )
    if self.machine.isVS2008():
      #conversion does not work on vs2008, so we copy a stored version of the vcproj
      self.copyfile(sys.path[0]+"/library/additions/cal3d-"+self.version+"/cal3d.vcproj", self.extractedpath+"\\src\\cal3d\\")
    else:  
      print( "using Universal lineending conversion and vcbuild /upgrade" )
      self.convertDspToVcProj("cal3d.dsp")

    if self.machine.bits == 64:
      self.convertProjTo64("cal3d.vcproj")
    
  def make(self):
    os.chdir( self.extractedpath+"\\src\\cal3d\\" )
    self.execute( "vcbuild /build cal3d.vcproj $ALL" )

  def install(self):
    os.chdir(self.extractedpath)
    installpath = self.installpath()
    bindir = installpath + "/bin"
    libdir = installpath + "/lib"
    includedir = installpath + "/include/cal3d"

    #dll binaries
    self.copyfile( "bin/Debug/cal3d_d.dll", bindir )
    self.copyfile( "bin/Release/cal3d.dll", bindir )
    #dynamic link libs
    self.copyfile( "bin/Debug/cal3d_d.lib", libdir )
    self.copyfile( "bin/Release/cal3d.lib", libdir )
    #headers
    self.copypattern("src/cal3d", "^.*\\.h$", includedir )
    

def decider( machine, dirs ):
    """ build cal3d for the machine in dirs """
    return {"Windows": Cal3dBuilder, "Linux": ConfigureMakeBuilder}[machine.platform]
BUILDER = decider
